import Calendar from '@/components/Calendar.vue'
import CaseCategory from '@/views/cases/CaseCategory.vue'
import CaseList from '@/views/cases/CaseList.vue'
import ClientList from '@/views/client/ClientList.vue'
import ForumList from '@/views/forum/ForumList.vue'
import LawerList from '@/views/lawer/LawerList.vue'
import LawerRecruit from '@/views/lawer/LawerRecruit.vue'
import Statistic from '@/views/statistic/Statistic.vue'
import { useEmployeeStore } from '@/stores'
import Announcement from '@/views/announcement/Announcement.vue'
import LayOutContainer from '@/views/layout/LayOutContainer.vue'
import Login from '@/views/user/Login.vue'
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      //默认页面
      path:'/',
      component:LayOutContainer,
      children:[
        {
          path:'/first',
          component:Announcement
        },
        {
          path:'/lawer/list',
          component:LawerList
        },
        {
          path:'/case/list',
          component:CaseList
        },
        {
          path:'/case/category',
          component:CaseCategory
        },
        {
          path:'/lawer/recruit',
          component:LawerRecruit
        },
        {
          path:'/forum',
          component:ForumList
        },
        {
          path:'/client/list',
          component:ClientList
        },
        {
          path:'/statistic',
          component:Statistic
        }
      ]
    },
    {
      path:'/login',
      component:Login
    },
  ],
})
//登陆访问拦截=>默认直接放行，根据返回值放行还是拦截
router.beforeEach((to)=>{
  //如果没有token且访问的是非登录页，拦截到登录，其他情况正常放行
  const employeeStore=useEmployeeStore()
  if(!employeeStore.token&&to.path!=='/login') return 'login'
})
export default router
